/*
 * CS_GUILD_BUFF_GACHYA.cpp
 *
 *  Created on: 2014. 7. 31.
 *      Author: mega
 */


#include "../../User.h"
#include "../../Command.h"
#include "../../Proxy.h"
#include "../../NLogic/VirtualCurrency.h"
#include "../../NResource/Static.h"
#include "../../NState/Static.h"

#include "../protocol/Guild.h"

namespace ProjectZ { namespace NCommand {

static void SendFail(User * pUser, int ack)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ack);
	pAck->MakePacket(CMD_SC_GUILD_BUFF_GACHYA);
	pUser->Send(pAck);
}

void Command::CS_GUILD_BUFF_GACHYA(User * pUser, ::Network::Packet * pPacket)
{
/*	CS_GUILD_BUFF_GACHYA				0x3202
	{

	}

	 길드 버프 뽑기 응답  - 박준성
	SC_GUILD_BUFF_GACHYA				0x3203
	{
		s16				s16ack;			/// ACK_OK: 성공
										///	ACK_NOT_ENOUGH_ZEN: 젠부족
										/// ACK_GUILD_PERMISSION_ERROR : 생성권한없음
		s16				s16Buff_skill_tid;//길드 버프 TID
		u8				u8Skill_level;//길드 버프 레벨
		s16				s16skill_value;
	}*/

	PREPARE_PACKET;

	if (0 >= pUser->GetUserInfo().guild_seq)
	{
		SendFail(pUser, ACK_UNKNOWN_ERROR);
		return;
	}

	// 젠 확인
	int vcIndex = static_cast<int>(EM_VCINDEX_GUILD_BUFF_GACHYA);
	NResource::VCResource::Flyweight * pFly = NResource::Static::InstancePtr()->GetVCRef()->GetFly(vcIndex);
	if (NULL == pFly)
	{
		DEBUGLOG("%s : pFly is NULL", __FUNCTION__);
		SendFail(pUser, ACK_UNKNOWN_ERROR);
		return;
	}

	if (pUser->GetVirtualCurrency()->GetZen() < (pFly->_VC_PRICE * -1))
	{
		SendFail(pUser, ACK_NOT_ENOUGH_ZEN);
		return;
	}

	GuildBuffGachyaSyn syn;
	syn.user_seq	= pUser->GetUserSeq();
	syn.guild_seq	= pUser->GetUserInfo().guild_seq;

	if (false == NProxy::SendGuildServer(pUser, syn))
	{
		SendFail(pUser, ACK_UNKNOWN_ERROR);
		return;
	}

	pUser->SetState(NState::Static::Instance().WAITGUILDINFO());
}

} /*NCommand*/ } /*ProjectZ*/

